


import {
  createStore,
  applyMiddleware, //调用中间件
  combineReducers //合并reducer
} from 'redux';

import countReducer from './reducers/countReducer';
import movieReducer from './reducers/movieReducer';

//异步处理中间件
//当我们要进行异步action，action是一个函数，我们dispacth的函数就会提交到中间件
//中间件帮我们执行函数，一般函数中会有一个dispatch再次派发到store中
import thunk from 'redux-thunk';

console.log('store 运行了');
//合并reducer
const allReducer = combineReducers({
  movie: movieReducer,
  count: countReducer
})

//创建一个store对象 需要使用redux提供的createStore方法 并且传入reducer和当前的store做关联
//创建store 并提供对应的reducer(第二个参数是用来调用中间件)
const store = createStore(allReducer, applyMiddleware(thunk));

//把store对象暴露出去
export default store;
